﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TreeGraphicalControl;
using FeatureModelCore;
using Collections.TreeCollections;
using System.Windows.Controls;
using FeatureModelTool.FeatureModelView.MenuItems;
using System.Windows;
using System.Windows.Media;

namespace FeatureModelTool.FeatureModelView.TreeViewItems
{
    public class TreeItem_Property : TreeViewItemControl
    {
        public FeatureNodeProperty FeatureInstance { get; protected set; }

        private readonly static string _ICON_SOURCE = "/FeatureModelTool;component/Images/p.png";
        private readonly static Color _COLOR = new Color() { R = 214, G = 227, B = 188 };
        private readonly static Brush _COMMON_COLOR = Brushes.Aqua;
        protected Brush Backgroud
        {
            get
            {
                if (FeatureInstance.ExistError)
                    return FeatureTreeView.ERROR_BACKGROUND;
                if (FeatureInstance.ExistWarning)
                    return FeatureTreeView.WARNING_BACKGROUND;
                return FeatureTreeView.COMMON_BACKGROUND;
            }
        }

        public TreeItem_Property(FeatureNodeProperty property)
        {
            FeatureInstance = property;
            this.Header = MainWindow.GenerateTreeItemHeader(this.FeatureInstance.ToString(), _ICON_SOURCE
                , Backgroud);
            //this.BorderBrush = Brushes.Black;
            //this.BorderThickness = new Thickness(1, 1, 1, 1);
        }
        /// <summary>
        /// Tree Item Construct
        /// </summary>
        /// <param name="treeObj"></param>
        /// <returns></returns>
        public static TreeViewItemControl ConstructTreeItem(TreeObject treeObj)
        {
            FeatureNodeProperty projFile = treeObj as FeatureNodeProperty;
            if (projFile == null)
            {
                return null;
            }
            return new TreeItem_Property(projFile);
        }
        /// <summary>
        /// Context Generator
        /// </summary>
        /// <param name="treeRoot"></param>
        /// <returns></returns>
        public static ContextMenu GenerateContext(TreeViewItemControl treeItem, TreeObject treeObj)
        {
            FeatureNodeProperty property = treeObj as FeatureNodeProperty;
            TreeItem_Property treeItemPro = treeItem as TreeItem_Property;
            if (property == null)
            {
                return null;
            }

            MenuItem_NodeProperty delete = new MenuItem_NodeProperty(treeItemPro, property)
            {
                Name = property.ID.ToString(),
                Header = "Delete"
            };
            delete.Click += new RoutedEventHandler(TreeItem_Root.Delete_EventHanlder);

            ContextMenu contextMenu = new ContextMenu();
            contextMenu.Items.Add(delete);
            return contextMenu;
        }
    }
}
